//////////////////////////////////////////////////////////////////////////
//	File	:	"SGD_Math.h"
//
//	Author	:	David Brown (DB)
//
//	Purpose	:	To do lots of math for us.
///////////////////////////////////////////////////////////////////////////
#ifndef MATHLIB_H_
#define MATHLIB_H_

const float SGD_PI = 3.141592653589732f;

//////////////////////////////////
//////////////////////////////////
//		class prototypes        //
//////////////////////////////////
//////////////////////////////////

//Tests to see if a number passed in is even or odd
//If the return value is true then the number is even
//else it is odd
bool IsEven(int Num);

//Produces a random number in a range passed in
int RandInt( int RangeLow, int RangeHigh);

float absolute(float value);

//	Define vector	-	used for movement or calculations
struct Vector2D
{
	float fX;
	float fY;
	
	Vector2D();
	Vector2D(float m_fX,float m_fY);

	Vector2D operator+(const Vector2D& v);
	Vector2D operator-(const Vector2D& v);
	Vector2D operator*(const float f);
	Vector2D operator/(const float f);

	///////////////////////////
	//Accessors and Mutators
	//////////////////////////
	//Accessors
	//////////////////////////
	//GetX returns a float
	float GetX() { return fX; }
	//GetY returns a float
	float GetY() { return fY; }
	///////////////////////////////
	//Mutators
	////////////////////////////////
	//SetX sets the members value to the one passed in
	void SetX(float ffX) { fX = ffX; }
	//SetY set the members value to the one passed in
	void SetY(float ffY) { fY = ffY; }

	//	Find the length of a vector (magnitude)
	float LengthOfVector(Vector2D vec);
};

float Vector2DLength(Vector2D vec);
// Find the dot product
float DotProduct(Vector2D v1, Vector2D v2);

//	Normalize a vector
Vector2D Vector2DNormalize(Vector2D vec);

//	Rotate a vector
/*
	X, Y	=	[X]
				[Y]
				[1]

	[	cos&	sin&	0	]		[X]		[X1]
	[  -sin&	cos&	0	]	*	[Y]	=	[Y1]
	[	0		0		1	]		[1]		[1]
*/
Vector2D Vector2DRotate(Vector2D vec, float fRadians);

//	Find the angle between 2 vectors
/*
	a . b = (||a|| ||b||) cos @

	cos @ = (a . b) / (||a|| ||b||)

	@ = arccos (a.b)
*/
float AngleBetweenVectors(Vector2D v1, Vector2D v2);

//	Linear Interpolation
//	v = a + ((b - a) * t)
float Lerp(float fStart, float fEnd, float fPercent);

//	Tests if two floats are approximately equal given a margin of error
bool FloatEquals(float fResult, float fExpected, float fEpsilon = 0.001f);

//	Determines which way to turn (counter clockwise (+) or clockwise (-))
float Steering(Vector2D vOrientation, Vector2D vToTarget);

float Round(float number);

bool IntersectCircle(const Vector2D& first, const float& firstradius, const Vector2D& second, const float& secondradius);

bool IntersectLineOfSight(Vector2D start, Vector2D end, float checkradius);

bool IntersectFlashlight(Vector2D enemy, Vector2D player, float radius, float currentrotation, float checkangle);

#endif